import React, { useEffect } from 'react'
import Footer from './Footer'
import Header from './Header'
import { useLocation } from 'react-router-dom'
import CenterList from './CenterList.jsx'
import '../assets/css/Center.css'
import store from '../redux/store'
import { changeNameAction } from '../redux/action'

export default function LaoBan() {
  let location = useLocation()
  let flag
  let title
  if (store.getState().IdentityMode.title !== '') {
    flag = store.getState().IdentityMode.title == '老板列表'
    title = store.getState().IdentityMode.title 
  } else {
    flag = location.state.title === '老板列表'
    store.dispatch(changeNameAction(location.state.title))
    title = location.state.title
  }
  let listUrl = flag ? 'http://127.0.0.1:8080/dashen/dashenPage' : 'http://127.0.0.1:8080/laoban/laobanPage'
  useEffect(() => {
    if(title == undefined) {
      store.dispatch(changeNameAction(location.state.title))
    }
  }, [])
  return (
    <div className='bigContainer'>
      <Header title={title}></Header>
      <CenterList flag={flag} listUrl={listUrl}></CenterList>
      <Footer></Footer>
    </div>
  )
}
